/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: LianBao
 * Date: 2024-09-01
 * Time: 13:15
 */
public class demo2 {
    public static void main1(String[] args) throws InterruptedException {
        Thread currentThread = Thread.currentThread();
        Thread t = new Thread(() -> {
            while (!currentThread.isInterrupted()) {
                System.out.println("Hello Thread");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    break;
                }
            }
        });
        t.start();
        Thread.sleep(3000);
        t.interrupt();
    }

    public static void main2(String[] args) throws InterruptedException {
        Thread t = new Thread(() -> {
            System.out.println("Hello Thread");
        });
        t.start();

        t.join();
        System.out.println("main");
    }

    public static void main3(String[] args) throws InterruptedException {
        Thread t1 = new Thread(() -> {
            System.out.println("t1");

        });
        Thread t2 = new Thread(() -> {
            System.out.println("t2");
        });
        t1.start();
        t2.start();
        t1.join();
        t2.join();
        System.out.println("main");
    }

    public static void main(String[] args) throws InterruptedException {
        Thread currentThread = Thread.currentThread();
        Thread t = new Thread(()->{
            System.out.println("t");
        });
        t.start();

        System.out.println("main");
    }
}
